a11y: Avoid spurious selection changed events
authorMatthias Clasen <mclasen@redhat.com>
Tue, 20 Apr 2021 17:23:56 +0000 (13:23 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Tue, 20 Apr 2021 17:23:56 +0000 (13:23 -0400)
Only send selection-changed events when we either
had a non-empty selection before, or have one now.

This should help orca speak the right things, and
not the wrong things.

Related: #3549

gtk/a11y/gtkatspitext.c

index 7cf08fdf0609423bc124ae0f8a6dad77288fe91d..44a5605716ad52acc6aed061f4fe3a8a2027864a 100644 (file)
@@ -1326,9 +1326,12 @@ update_selection (TextChanged *changed,
                   int          selection_bound)
 {
   gboolean caret_moved, bound_moved;
+  gboolean had_selection, has_selection;
 
   caret_moved = cursor_position != changed->cursor_position;
   bound_moved = selection_bound != changed->selection_bound;
+  had_selection = changed->cursor_position != changed->selection_bound;
+  has_selection = cursor_position != selection_bound;
 
   if (!caret_moved && !bound_moved)
     return;
@@ -1339,7 +1342,7 @@ update_selection (TextChanged *changed,
   if (caret_moved)
     changed->selection_changed (changed->data, "text-caret-moved", changed->cursor_position);
 
-  if (caret_moved || bound_moved)
+  if (had_selection || has_selection)
     changed->selection_changed (changed->data, "text-selection-changed", 0);
 }